# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libidn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.36
pkgrel=1
pkgdesc="Implementation of the Stringprep, Punycode and IDNA specifications (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.gnu.org/software/libidn"
license=("GPL3, LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "gtk-doc")
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
options=('staticlibs' 'strip')
source=("https://ftp.gnu.org/gnu/libidn/${_realname}-${pkgver}.tar.gz"
        0002-fix-gdoc.all.patch
        0003-nfkc.c-Fix-Win64-crash.patch
        0004-nfkc.c-Fixed-invalid-var-types.patch)
sha256sums=('14b67108344d81ba844631640df77c9071d9fb0659b080326ff5424e86b14038'
            '02d9b9e6e3f966cff2d4d763c0de9219da6c8cf444248011caa8eb2fb3067a24'
            '6293c730a98af32a337149a95d848f3c4619df8dc367e0bf0251a509b09f5963'
            '8ae6ad9513fc11bd79cb1ab73f187cb8297bdabd21a2aef3b6526ca17810eda9')

prepare() {
  
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/0002-fix-gdoc.all.patch
  patch -p1 -i ${srcdir}/0003-nfkc.c-Fix-Win64-crash.patch
  patch -p1 -i ${srcdir}/0004-nfkc.c-Fixed-invalid-var-types.patch
  
  autopoint --force
  autoreconf -i
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX}\
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-csharp \
    --disable-java \
    --disable-rpath \
    --enable-threads=win32

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
